package com.crazyhat.crazyhat.vaildation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.crazyhat.crazyhat.anno.ClubCategoryAnno;
import com.crazyhat.crazyhat.pojo.ClubCategory;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import lombok.Data;

/**
 * 社团分类校验
 */
@Component
@Data
public class ClubCategoryValidation implements ConstraintValidator<ClubCategoryAnno,String>{

    @Autowired
    private ClubCategory clubCategory;

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {

        if (value==null || clubCategory.getClubCategoryList()==null) {

            System.out.println("ClubCategoryList为空");
            
            return true;
        }

        //验证是否为有效社团类别
        for(String item:clubCategory.getClubCategoryList()) {
            if (item.equals(value)) {
                return true;
            }
        }

        return false;
    }
}
